package com.vnp.cooking.frgDetail;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import com.actionbarsherlock.app.SherlockListFragment;
import com.vnp.cooking.R;
import com.vnp.cooking.adapter.ListCommentAdapter;
import com.vnp.cooking.bean.ObjComment;

public class FrgBinhluan extends SherlockListFragment implements OnClickListener{
	
	View v;
	ListView lsComment;
	ListCommentAdapter lsCommentAdapter;
	EditText edtComment;
	Button btnSendComment;
	ArrayList<ObjComment> objComments = new ArrayList<ObjComment>();
	//demo avatar url
	String urlImageDemo = "http://images1.fanpop.com/images/photos/1800000/Leah-s-photoshoot-for-website-profile-leah-dizon-1856157-531-800.jpg";
	

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		v = (View) inflater.inflate(R.layout.activity_comment, container, false);
		
		edtComment = (EditText) v.findViewById(R.id.edt_create_comment);
		btnSendComment = (Button) v.findViewById(R.id.btn_send_comment);
		
		init();
		return v;
	}
	
	
	void init() {
		btnSendComment.setOnClickListener(this);
	}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		lsCommentAdapter = new ListCommentAdapter(getActivity(), objComments);
		getListView().setAdapter(lsCommentAdapter);
	}


	@Override
	public void onClick(View v) {	
		switch (v.getId()) {
		case R.id.btn_send_comment:
			addCommentToList();
			break;

		default:
			break;
		}
		
	}
	
	public void addCommentToList() {
		if (edtComment.getText().toString().matches("")){
			
		} else {
			ObjComment objComment = new ObjComment(urlImageDemo, "Thientv", "1h", edtComment.getText().toString());
			objComments.add(objComment);
			edtComment.setText("");
			getListView().setSelection(objComments.size());
//			lsComment.setSelection(objComments.size());
		}
		
//		lsCommentAdapter.notifyDataSetChanged();
	}

}
